package Operation;

import Book.BookList;

import java.util.Scanner;

public class BorrowOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("请输入你要借阅的书籍的名字：");
        Scanner input = new Scanner(System.in);
        String name = input.nextLine();
        for(int i = 0; i < bookList.getBookSize(); i++){
            if (name.equals(bookList.getBook(i).getName())){
                if (!bookList.getBook(i).getBorrowed()){
                    bookList.getBook(i).setBorrowed(true);
                    System.out.println("借阅成功！");
                    System.out.println(bookList.getBook(i));
                }else{
                    System.out.println("借阅失败，该图书早已借出！");
                }
                return;
            }else{
                System.out.println("没有找到该书！");
            }
        }
    }
}
